using System;

namespace App.Practice.Step04
{
   public class Demo
   {
      public static void Run()
      {
         Copier.reader = new PaperTape();
         Copier.writer = new PaperTape();
         Copier.Copy();
      }
   }

   interface IReader
   {
      char Read();
   }

   interface IWriter
   {
      void Write(char c);
   }

   internal static class Copier
   {
      // The agile way - first change request revisited

      public static IReader reader;
      public static IWriter writer;

      public static void Copy()
      {
         if (reader == null || writer == null) return;

         char c;
         while (Char.ToLower(c = reader.Read()) != 'x')
            writer.Write(c);
      }
   }

   internal class Keyboard : IReader
   {
      public char Read()
      {
         return Console.ReadKey().KeyChar;
      }
   }

   internal class Printer : IWriter
   {
      public void Write(char c)
      {
         Console.Write(c);
      }
   }

   internal class PaperTape : IReader, IWriter
   {
      public char Read()
      {
         return char.ToUpper(Console.ReadKey().KeyChar);
      }

      public void Punch(char c)
      {
         Console.Write("::" + c);
      }

      public void Write(char c)
      {
         Punch(c);
      }
   }
}